package org.example.admincontroller;

import lombok.extern.slf4j.Slf4j;
import org.example.adminservice.SalelogService;
import org.example.pojo.PageBean;
import org.example.pojo.Result;
import org.example.pojo.admindto.SaleLogDTO;
import org.example.pojo.admindto.SaleTableDTO;
import org.example.pojo.adminvo.SaleLogVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/admin/salelog")
public class SalelogController {

    @Autowired
    private SalelogService salelogService;

    @GetMapping("/list")
    public Result saleloglist(@RequestParam(defaultValue = "1") int page,
                              @RequestParam(defaultValue = "10") int pageSize,
                              @RequestParam(value = "username", required = false) String username,
                              @RequestParam(value = "goodname", required = false) String goodname,
                              @RequestParam(value = "state", required = false) Integer state) {
        SaleLogDTO saleLogDTO = new SaleLogDTO(page, pageSize, username, goodname, state);
        if(saleLogDTO.getPage()==null){
            saleLogDTO.setPage(1);
        }
        if(saleLogDTO.getPageSize()==null){
            saleLogDTO.setPageSize(10);
        }
        PageBean pageBean = salelogService.saleLog( saleLogDTO );
        SaleLogVO saleLogVO = new SaleLogVO(pageBean);
        return Result.success(saleLogVO);
    }
}
